##################################################################################
#                                                                                #
#Rodolfo Espino and Michael Franz                                                #
#Replicate 99th and Extend to 105th                                              #
#First Update: July 4, 2002                                                      #
#                                                                                #
#Last Update: Cinco De Mayo, 2003                                                #
##################################################################################


#################################################################################
#################################################################################
#################################################################################
#################################################################################

####99TH  CONGRESS


#the following are the data used by Groseclose (I think the 99th Congress)

state<-c(1,1,1,1,1,1,1,2,3,3,3,3,3,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
    5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,7,7,7,7,
    7,7,8,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,
    10,11,11,12,12,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
    13,13,13,14,14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,16,16,16,16,16,
    17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,19,19,20,20,20,20,20,20,20,
    20,21,21,21,21,21,21,21,21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,22,
    22,22,22,22,22,23,23,23,23,23,23,23,23,24,24,24,24,24,25,25,25,25,25,25,
    25,25,25,26,26,27,27,27,28,28,29,29,30,30,30,30,30,30,30,30,30,30,30,30,
    30,30,31,31,31,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
    32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,33,33,33,33,33,33,33,33,33,
    33,33,34,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,
    36,36,36,36,36,36,37,37,37,37,37,38,38,38,38,38,38,38,38,38,38,38,38,38,
    38,38,38,38,38,38,38,38,38,38,39,39,40,40,40,40,40,40,41,42,42,42,42,42,
    42,42,42,42,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,
    43,43,43,43,43,43,43,44,44,44,45,46,46,46,46,46,46,46,46,46,46,47,47,47,
    47,47,47,47,47,48,48,48,48,49,49,49,49,49,49,49,49,49)
district<-c(1,2,3,4,5,6,7,0,1,2,3,4,5,1,2,3,4,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
    16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,
    40,41,42,43,44,45,1,2,3,4,5,6,1,2,3,4,5,6,0,1,2,3,4,5,6,7,8,9,10,11,12,
    13,14,15,16,17,18,19,1,2,3,4,5,6,7,8,9,10,1,2,1,2,1,2,3,4,5,6,7,8,9,10,
    11,12,13,14,15,16,17,18,19,20,21,22,1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,1,
    2,3,4,5,1,2,3,4,5,6,7,1,2,3,4,5,6,7,8,1,2,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,
    9,10,11,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,1,2,3,4,5,6,7,8,1,
    2,3,4,5,1,2,3,4,5,6,7,8,9,1,2,1,2,3,1,2,1,2,1,2,3,4,5,6,7,8,9,10,11,12,
    13,14,1,2,3,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,
    24,25,26,27,28,29,30,31,32,33,34,1,2,3,4,5,6,7,8,9,10,11,0,1,2,3,4,5,6,
    7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,1,2,3,4,5,6,1,2,3,4,5,1,2,3,4,
    5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,1,2,1,2,3,4,5,6,0,1,
    2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,
    22,23,24,25,26,27,1,2,3,0,1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,1,2,3,4,
    1,2,3,4,5,6,7,8,9)
party<-c(0,0,1,1,1,1,1,0,0,1,0,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,0,1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,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,1,0,0,
    0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1,0,0,0,
    0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,1,1,0,0,
    0,0,0,0,1,0,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,
    0)
asc<-c(100,100,100,80,89,80,100,100,100,11,100,100,100,25,80,100,25,10,100,0,20,0,
    0,0,0,0,0,10,78,0,100,0,0,100,0,100,90,100,100,0,0,0,0,0,0,0,10,0,30,100,
    0,100,0,100,100,100,100,100,100,100,10,100,10,10,100,80,100,89,0,0,0,11,
    90,50,20,100,78,50,100,100,10,40,100,100,100,75,90,100,50,100,33,0,63,40,
    80,75,100,100,33,100,100,90,80,90,38,10,100,30,0,0,0,83,78,100,0,0,0,70,
    10,89,90,100,100,90,0,100,0,0,40,22,0,20,100,90,100,100,90,22,30,0,10,20,
    40,0,80,0,70,30,80,20,90,90,20,30,100,100,90,0,100,30,90,90,67,100,100,
    33,50,60,100,89,0,100,20,90,0,0,0,0,0,0,0,0,0,0,0,0,11,60,0,100,50,10,
    0,0,90,100,89,0,0,0,0,10,0,100,0,90,70,0,0,0,100,0,50,90,100,50,100,0,
    20,22,90,0,100,100,100,20,10,100,80,90,80,20,100,100,80,0,20,0,60,60,0,
    70,0,0,0,90,100,80,0,100,100,20,100,0,0,100,80,0,0,0,0,0,0,0,0,90,10,0,
    0,0,40,70,56,90,100,100,40,100,78,0,33,100,100,10,0,10,10,70,60,100,40,
    100,22,63,100,100,100,10,0,60,11,100,100,100,100,90,0,100,0,100,0,0,100,
    80,0,0,0,0,0,60,0,60,50,100,100,0,89,0,0,100,0,0,0,0,100,20,0,0,100,80,
    20,90,30,0,100,90,100,10,80,25,44,10,70,0,10,100,100,22,100,50,60,0,90,
    100,100,30,30,20,100,40,0,0,67,90,90,20,100,100,90,10,40,100,13,100,100,
    33,40,100,0,100,0,100,100,50,40,60,90,60,100,100,100,0,100,90,100,80,
    100,10,100,100,10,100,70,0,0,90,0,20,0,67,50,20,0,0,60,0,70,10,0,90,0,
    90,80)
bipac<-c(98,95,55,18,23,37,44,53,98,4,100,89,98,7,45,89,19,8,91,0,4,0,0,2,4,4,0,
    0,93,2,98,4,7,87,4,96,94,100,100,4,0,0,0,0,2,2,2,2,13,100,0,77,3,100,98,
    98,100,82,98,95,13,98,24,20,97,98,97,95,0,4,2,23,87,67,40,71,25,25,25,
    93,33,43,98,97,98,41,98,100,15,98,7,0,0,0,44,26,82,100,34,95,69,38,52,
    64,21,2,100,52,2,4,13,44,4,96,0,0,2,84,2,100,93,48,85,98,0,95,17,10,0,
    0,8,30,100,98,94,95,72,11,40,33,72,93,89,13,94,17,93,46,87,33,98,76,13,
    24,85,93,100,4,93,2,66,70,57,98,36,4,91,87,45,75,6,86,4,68,2,7,23,0,5,
    4,5,5,0,0,2,3,8,88,13,100,87,40,2,9,98,96,46,2,5,11,4,2,2,91,47,91,95,4,
    0,4,78,2,24,88,74,30,97,2,14,0,14,0,96,91,94,34,0,95,85,94,91,15,95,98,
    96,7,44,4,34,87,0,28,4,10,0,83,75,83,4,92,91,0,93,0,7,75,66,0,0,2,0,6,
    0,0,2,67,36,0,0,0,2,87,54,34,25,95,55,95,87,0,24,95,74,13,7,12,19,46,
    34,100,33,100,15,26,100,100,93,28,13,89,13,98,98,93,94,100,10,97,17,98,
    13,0,85,76,17,33,8,0,2,58,24,38,48,95,70,25,95,27,9,100,0,2,2,11,90,21,
    3,6,98,45,17,4,65,0,85,100,87,16,96,11,68,21,53,2,45,100,98,25,100,24,
    41,19,74,83,58,25,23,26,98,27,7,51,19,98,77,13,100,100,98,9,41,74,7,98,
    97,4,13,81,2,100,0,100,100,2,16,46,100,2,98,100,98,51,85,91,96,28,80,
    51,100,89,7,83,80,2,2,83,2,4,6,95,13,6,11,2,4,4,87,0,7,81,6,98,96)
ccus<-c(87,77,72,32,36,47,48,50,75,16,97,72,91,26,44,77,36,28,87,17,28,12,16,17,
    15,13,15,26,92,18,92,20,31,70,20,85,94,92,97,21,23,17,21,21,20,18,13,21,
    23,97,21,63,24,92,81,91,94,80,95,94,42,88,42,46,94,88,94,89,31,32,25,52,
    79,68,50,87,55,41,32,86,61,53,71,72,91,57,81,93,47,84,30,22,20,17,53,55,
    85,94,50,94,73,50,51,64,40,20,95,63,10,12,37,62,20,74,11,35,16,88,31,87,
    92,43,75,87,14,84,34,29,29,36,34,45,92,90,82,87,61,40,56,54,55,85,75,23,
    88,41,94,46,82,45,90,59,25,37,67,71,87,20,82,27,68,69,72,95,43,36,72,60,
    50,68,26,66,27,61,19,33,27,22,20,20,29,25,21,20,23,26,18,75,26,92,78,41,
    21,28,89,70,56,15,16,23,13,15,32,85,50,74,85,23,14,30,63,12,25,94,79,37,
    90,19,31,18,40,18,75,73,76,34,21,76,77,75,77,38,92,97,87,14,31,20,37,73,
    22,34,23,16,19,64,59,69,18,78,76,36,75,21,37,60,60,4,16,20,28,30,15,17,
    20,68,48,10,21,18,24,77,49,27,29,84,56,75,73,17,33,90,68,31,27,31,32,62,
    49,90,49,90,34,38,95,95,76,28,33,89,42,95,86,79,79,82,37,81,29,87,27,20,
    72,60,27,42,32,17,18,60,29,37,72,83,71,48,95,43,33,91,14,24,28,28,81,37,
    19,37,90,36,30,19,59,20,88,92,78,35,82,31,67,34,50,27,45,94,85,40,85,58,
    47,30,63,70,49,49,29,42,81,37,11,71,35,97,73,42,94,97,92,30,43,63,34,92,
    94,29,44,82,11,92,15,93,94,22,39,66,97,22,89,97,94,57,77,81,85,46,77,61,
    94,73,34,70,76,22,30,74,30,33,16,83,23,33,27,17,26,20,74,24,18,76,15,88,
    87)
cope<-c(20,28,35,66,65,75,71,57,13,87,4,14,6,91,74,13,56,81,8,86,87,100,100,85,92,
    85,96,97,21,86,9,94,78,48,94,6,18,3,3,69,93,89,93,83,100,100,100,89,83,0,
    93,21,92,3,10,3,7,7,6,6,80,24,78,81,7,6,12,14,93,97,96,86,51,63,78,27,56,
    76,58,6,49,42,16,29,7,51,13,12,61,13,97,91,100,93,42,57,23,10,46,13,37,45,
    41,33,79,86,10,48,100,100,84,31,96,14,100,83,86,15,96,3,10,0,27,28,96,7,
    88,87,100,91,82,78,6,16,24,10,27,81,63,72,37,22,17,79,19,85,9,58,16,61,13,
    74,84,55,13,30,22,90,16,94,51,37,36,14,76,97,42,58,64,45,96,16,93,46,93,
    100,100,94,96,90,86,93,92,100,93,96,92,33,93,7,33,81,100,94,10,14,78,97,
    92,90,96,89,94,10,55,17,9,96,93,94,10,96,72,27,23,73,17,100,80,94,73,93,
    25,21,27,69,93,12,16,12,10,87,10,16,25,100,80,100,90,34,100,90,97,100,100,
    43,46,34,93,21,6,88,3,86,83,38,42,50,100,100,90,89,96,96,90,35,63,96,89,
    100,100,49,68,87,81,23,79,44,46,82,90,6,21,88,100,94,74,39,47,21,62,24,
    61,55,21,22,27,73,78,7,76,3,16,18,16,20,90,7,81,20,80,83,30,53,100,76,91,
    93,96,48,55,55,38,7,37,78,13,75,96,17,97,92,94,84,37,84,96,88,26,84,84,
    87,65,100,47,13,32,87,31,85,55,84,72,100,83,14,27,55,39,51,62,62,28,28,62,
    67,90,74,16,57,92,44,83,3,32,90,3,0,3,100,55,32,90,7,11,80,78,22,93,10,
    90,8,3,94,77,57,3,86,0,6,7,68,6,7,19,50,27,49,13,30,75,22,30,77,83,33,84,
    83,79,19,91,91,87,90,90,90,48,84,93,17,93,10,6)
ibt<-c(15,36,44,85,75,83,85,92,8,100,0,0,8,100,100,15,62,92,10,92,100,100,100,92,
    100,92,100,100,10,92,0,100,92,67,100,8,8,0,8,69,92,100,92,82,100,100,100,
    100,77,0,100,15,100,0,10,0,0,0,0,0,92,15,85,92,8,8,25,8,100,100,100,100,
    62,69,100,23,58,77,38,0,33,46,0,15,0,36,0,0,69,0,100,100,100,100,62,50,
    38,8,60,8,36,54,38,54,100,92,8,75,100,100,100,20,100,0,100,92,100,0,100,
    0,8,0,36,38,100,8,100,100,100,100,100,100,8,15,18,23,15,100,77,100,46,31,
    14,90,0,100,0,92,8,92,0,92,100,69,0,23,8,100,8,100,46,46,31,9,92,100,42,
    62,92,50,100,0,100,31,92,100,100,100,100,100,100,100,100,100,100,100,100,
    31,100,0,38,100,100,100,8,31,100,100,100,100,100,100,100,8,77,15,8,100,
    100,100,15,100,62,23,23,69,23,100,100,100,100,100,23,18,15,100,100,0,8,
    15,8,85,0,8,38,100,92,100,100,46,100,100,100,100,100,54,54,54,100,14,8,
    100,18,92,92,45,54,0,100,100,100,92,100,100,92,46,50,100,92,100,100,62,
    69,100,92,9,85,50,46,77,100,0,46,92,100,92,67,23,23,23,62,23,67,38,23,18,
    23,92,92,8,85,0,20,23,0,25,100,15,100,23,92,92,42,77,100,100,100,100,100,
    78,77,62,55,8,46,77,0,77,100,9,100,100,100,100,31,100,100,100,23,100,100,
    100,85,100,77,0,8,100,38,100,92,100,100,100,92,9,23,54,50,54,62,92,31,15,
    78,77,92,100,23,56,100,62,92,0,36,100,0,0,0,100,69,17,100,8,15,92,77,23,
    100,15,100,14,0,100,92,77,0,92,0,0,31,62,0,13,8,56,18,62,8,8,85,0,46,92,
    92,23,100,92,85,8,100,100,100,100,100,100,62,92,100,38,100,8,15)
mnpl<-c(22,31,49,85,67,76,72,81,9,94,0,0,9,90,94,36,72,74,14,81,100,100,100,79,
    100,81,100,100,5,81,0,100,81,45,100,9,23,14,0,73,81,84,81,77,100,100,100,
    78,77,0,100,5,100,0,0,5,0,0,0,0,82,23,62,81,0,5,16,5,100,100,100,100,26,
    36,82,39,60,73,59,0,29,50,9,23,0,50,0,5,54,5,100,100,100,100,55,63,36,18,
    67,23,50,55,64,52,65,78,4,50,100,100,96,6,100,0,100,80,85,5,100,0,0,0,35,
    14,100,0,100,100,100,100,95,76,0,5,38,0,18,95,68,76,56,14,10,78,14,94,5,
    68,15,68,14,76,100,63,19,45,23,100,8,100,60,23,52,16,65,100,41,54,81,40,
    100,5,100,57,96,100,100,100,100,100,94,100,100,100,100,100,84,17,100,5,
    41,85,100,100,0,23,95,100,80,100,100,100,100,5,46,10,11,100,86,100,8,100,
    86,36,45,65,26,100,100,100,100,100,27,33,46,100,100,10,18,10,10,94,0,18,
    27,100,82,100,100,34,100,100,100,100,100,17,17,12,100,30,18,95,6,81,91,
    26,33,100,100,95,100,80,100,100,81,14,33,100,96,100,100,36,72,86,91,21,
    81,47,22,73,100,0,4,81,100,81,57,41,54,26,67,31,72,65,26,37,31,77,72,0,
    91,0,5,9,5,31,100,11,100,13,81,80,29,63,100,91,100,100,100,44,44,49,42,
    0,26,54,17,54,100,10,95,100,100,90,36,90,100,100,41,72,91,100,72,100,79,
    5,23,96,26,85,81,100,100,100,71,23,31,59,30,68,54,71,40,36,75,86,91,86,
    27,54,100,46,95,0,48,100,0,0,0,100,50,47,100,4,9,95,81,31,100,13,91,21,
    0,100,100,64,0,95,0,19,4,77,14,7,23,59,48,67,18,28,76,10,22,81,80,36,85,
    81,77,9,100,100,100,100,100,100,58,72,100,37,100,11,0)
rlea<-c(30,30,67,86,78,80,67,44,22,100,0,25,10,100,67,60,89,89,14,100,89,100,100,
    90,89,100,100,90,22,100,20,100,78,38,89,20,22,13,10,100,100,90,100,100,
    100,100,90,100,100,0,90,38,100,0,25,11,25,11,10,10,70,14,67,67,25,0,25,
    22,100,90,100,83,40,70,90,50,71,90,100,0,67,71,44,38,22,71,20,20,90,25,
    90,100,100,89,70,67,40,10,67,20,60,80,80,70,57,86,11,70,100,100,70,63,
    100,29,100,89,100,30,100,13,30,29,33,10,100,30,80,90,100,89,80,80,11,30,
    33,10,50,80,70,50,44,20,44,89,50,67,30,70,60,78,30,50,90,70,38,60,30,100,
    22,100,50,30,60,33,57,86,50,50,70,60,90,60,90,80,89,89,90,100,100,100,78,
    90,100,100,100,100,75,43,90,40,50,67,90,100,38,30,63,100,100,80,100,100,
    90,30,60,33,20,100,100,90,40,100,100,33,80,88,11,90,88,88,71,100,30,67,
    60,80,89,60,40,40,50,80,0,10,11,100,70,100,70,60,100,67,89,100,100,30,30,
    30,100,50,40,70,30,100,80,67,56,100,100,100,89,100,100,100,100,30,70,100,
    100,90,100,50,50,90,80,11,50,70,56,100,70,30,22,90,90,88,100,60,67,11,63,
    33,89,90,33,22,56,70,80,50,75,11,20,22,40,10,67,25,80,20,90,100,60,60,90,
    70,80,90,90,70,90,70,60,11,40,67,33,70,89,20,100,100,100,80,44,80,100,90,
    33,80,90,100,50,100,40,20,40,90,30,60,50,80,70,100,75,17,0,90,0,90,90,60,
    50,50,60,80,80,80,20,67,100,43,78,10,40,80,10,11,25,89,89,50,89,20,10,89,
    70,30,100,10,80,0,11,80,86,60,0,90,30,11,10,60,20,22,20,90,40,70,20,70,
    80,80,40,90,100,50,90,75,100,40,90,80,90,100,100,100,50,89,100,30,100,0,
    10)
nea<-c(0,21,50,83,85,85,85,65,27,100,0,12,0,100,85,50,84,85,17,100,100,100,100,100,
    100,100,100,85,27,100,15,100,85,7,100,21,34,0,0,100,100,100,100,100,100,
    100,100,100,100,0,85,41,100,0,29,15,0,6,0,0,85,15,100,85,0,29,15,29,100,
    85,100,100,56,79,85,29,85,79,100,0,85,58,41,27,0,79,12,15,71,27,85,100,
    100,85,71,85,29,0,83,29,50,85,85,58,80,85,0,75,100,100,85,33,100,24,100,
    85,100,29,100,15,15,0,50,15,100,0,85,85,100,85,100,85,15,29,12,0,56,85,79,
    79,65,35,79,100,35,83,29,79,44,85,15,85,85,85,27,41,44,100,21,100,73,44,
    58,33,83,100,65,50,85,35,100,35,100,56,100,100,100,100,100,100,85,85,100,
    100,100,100,84,48,85,17,35,83,100,100,0,6,85,100,100,85,100,100,85,35,50,
    29,17,100,100,85,29,100,100,21,29,100,0,100,83,85,85,100,65,21,75,85,100,
    50,50,35,41,85,21,0,29,100,100,100,85,50,100,85,100,100,100,41,56,41,100,
    15,21,83,0,100,85,35,50,100,100,100,85,100,100,100,100,29,85,100,100,100,
    100,35,75,85,100,15,71,79,50,100,85,15,29,100,100,83,100,85,85,6,85,15,
    100,85,15,17,56,100,85,0,85,0,0,15,21,0,85,0,85,29,85,100,71,50,100,71,85,
    100,100,79,100,85,79,0,50,71,15,85,100,15,100,100,100,85,35,71,100,85,15,
    71,85,100,71,100,15,15,44,85,56,85,35,85,65,100,79,15,6,100,41,83,100,83,
    50,73,79,73,83,85,29,85,100,73,79,0,29,85,0,0,0,100,79,41,85,0,0,100,85,
    44,100,0,85,0,0,100,85,79,0,100,0,29,0,71,6,21,21,85,21,79,0,35,85,56,35,
    85,100,85,85,100,100,41,100,85,85,100,100,100,41,85,100,29,100,7,0)
lcv<-c(11,13,6,25,50,56,38,17,29,69,11,7,41,59,50,22,63,76,13,82,47,71,100,87,94,
    100,89,75,53,67,17,50,82,22,63,28,29,27,18,88,100,65,94,89,65,53,76,73,
    67,39,72,19,87,17,17,33,13,22,35,18,94,24,100,81,12,33,22,18,89,94,88,57,
    50,61,83,38,60,67,31,44,83,71,28,24,24,57,29,28,56,29,88,56,65,78,56,43,
    39,35,77,31,44,44,50,38,58,60,11,53,71,83,71,17,56,29,82,50,94,61,72,29,
    72,9,31,28,100,6,78,76,63,47,67,89,35,33,27,25,12,67,65,78,89,44,44,50,
    22,89,22,56,75,67,33,24,44,35,12,11,22,39,11,53,35,71,53,15,33,64,67,72,
    50,22,69,25,56,39,92,100,83,69,76,100,78,71,100,78,100,71,100,43,94,31,
    67,44,89,47,33,24,50,88,75,89,75,67,83,41,67,60,50,100,67,83,18,72,27,13,
    22,50,12,93,44,75,35,83,11,17,6,39,67,17,28,33,18,65,12,50,71,78,72,67,
    72,56,67,67,61,78,75,56,39,50,72,18,6,82,31,87,81,27,35,75,89,72,47,88,
    69,76,88,39,89,72,100,76,65,33,72,67,35,33,78,18,39,72,53,24,7,53,61,71,
    41,39,44,24,82,22,44,36,22,38,11,61,44,35,78,24,19,31,41,47,69,20,78,22,
    72,94,18,33,67,53,78,76,81,53,78,29,50,11,33,76,22,78,87,18,88,81,69,41,
    13,69,94,100,11,41,56,38,83,61,47,39,22,81,33,56,50,61,33,80,88,31,22,75,
    15,71,47,71,13,11,25,75,56,47,28,36,73,58,44,47,25,83,44,41,29,64,56,13,
    40,11,35,53,72,22,78,28,72,15,6,53,53,65,39,50,19,6,17,82,12,13,11,39,41,
    61,12,18,65,28,82,61,76,33,61,61,94,44,33,65,65,61,71,100,33,67,81,72,83,
    39,56)
pccw<-c(13,8,27,25,38,47,29,7,21,77,7,25,18,73,53,21,50,54,14,100,62,100,86,77,93,
    83,100,85,8,93,7,42,57,23,57,7,0,0,7,93,100,87,93,100,85,85,80,75,67,7,83,
    20,83,7,7,8,8,0,13,17,80,15,87,69,7,7,0,8,100,80,100,33,27,33,53,25,30,60,
    42,13,79,85,20,14,15,56,8,13,69,20,87,85,86,87,40,38,33,7,38,15,33,40,47,
    55,44,73,0,29,87,85,77,0,80,29,85,70,100,27,87,21,33,0,27,13,100,14,73,
    67,56,42,67,73,8,20,0,7,13,67,50,67,73,40,31,71,13,73,13,40,47,47,7,20,
    40,47,29,14,14,60,8,79,40,67,50,0,50,69,53,53,27,13,91,21,73,36,85,85,87,
    82,91,80,73,79,93,86,92,86,92,29,92,0,36,40,93,85,7,8,27,92,80,93,93,77,
    86,29,67,18,14,100,93,93,25,93,54,9,27,50,8,92,43,80,47,100,20,20,0,53,
    60,7,33,13,8,87,13,20,33,93,87,93,60,46,92,79,79,100,100,36,33,33,93,0,0,
    62,29,93,69,31,57,100,100,93,64,93,87,100,100,47,67,100,100,100,85,27,57,
    60,64,7,64,21,21,93,54,13,30,93,93,77,57,27,54,15,67,14,47,45,0,0,0,71,
    53,23,79,13,27,8,33,18,71,0,60,7,80,93,40,43,80,36,73,83,92,33,79,29,40,
    13,27,64,7,80,92,7,93,92,73,47,17,69,100,80,13,57,71,46,43,93,0,13,20,73,
    20,47,47,50,29,100,75,9,0,60,0,53,23,67,25,20,20,69,54,47,13,40,73,36,15,
    7,36,69,8,0,7,78,43,14,53,7,0,43,60,14,83,7,93,10,0,58,57,40,0,67,23,0,7,
    53,0,8,7,27,27,47,0,13,77,27,53,80,77,13,67,73,93,20,33,80,71,79,92,93,
    13,93,100,60,93,7,36)
nfu<-c(25,47,57,75,69,66,70,47,22,95,21,14,17,95,78,50,83,60,19,96,91,100,100,95,
    96,87,96,90,9,95,12,96,87,51,95,12,34,8,8,69,75,95,81,70,95,100,100,94,
    67,4,95,29,81,8,8,8,4,16,8,4,62,45,60,84,26,16,30,8,75,79,69,60,16,37,50,
    65,72,83,79,4,54,46,13,21,21,45,25,8,71,9,69,73,86,81,62,71,47,8,83,26,
    62,58,59,51,83,92,29,74,100,100,81,22,73,14,88,69,74,4,83,7,8,13,34,26,
    100,19,83,79,87,87,66,75,8,17,27,13,50,73,62,58,58,37,48,86,37,87,33,62,
    13,62,29,61,87,58,37,54,33,91,17,87,62,54,77,50,73,80,41,54,62,44,87,9,
    87,60,96,83,50,77,73,68,63,82,74,81,75,87,94,22,87,32,41,87,96,96,13,56,
    56,100,96,87,100,100,87,9,75,48,26,87,91,96,41,100,95,41,44,80,27,100,96,
    91,86,96,50,50,62,92,100,44,58,33,61,73,12,4,4,91,66,87,50,22,83,39,96,
    90,94,17,17,21,96,30,39,92,4,83,60,12,13,50,85,91,91,72,95,91,74,12,21,
    100,79,83,79,17,45,71,70,16,54,50,29,83,71,8,23,75,83,79,86,75,78,33,87,
    30,91,86,30,27,46,96,46,17,74,21,23,37,16,40,79,26,83,33,69,81,27,42,96,
    91,79,100,100,79,78,79,74,46,79,58,36,54,94,15,91,96,87,95,18,72,89,62,
    17,50,91,91,29,91,19,0,12,83,33,95,52,87,51,82,42,25,45,91,36,66,81,91,
    43,46,68,75,78,83,42,78,92,69,76,0,73,87,16,0,0,91,74,52,94,25,44,90,87,
    37,91,42,100,26,0,86,81,61,0,84,5,8,4,66,29,18,25,74,46,50,21,29,79,20,
    21,83,87,42,90,79,82,17,87,83,83,91,81,96,62,82,82,37,91,38,16)
ncsc<-c(5,10,55,94,84,89,74,45,26,95,0,18,10,95,50,25,84,90,21,95,90,100,100,89,
    100,89,100,100,15,95,10,100,89,40,100,20,5,13,5,89,100,100,100,94,100,
    100,100,100,90,5,95,34,94,5,10,6,5,30,5,10,80,10,89,84,10,0,10,5,95,100,
    89,77,50,45,60,35,87,85,94,23,80,61,27,38,10,42,25,10,95,20,100,100,100,
    100,75,95,5,5,83,5,72,85,80,60,67,100,5,57,100,95,80,62,90,24,100,90,94,
    5,89,5,5,5,40,15,100,20,90,100,94,95,85,84,5,15,29,5,35,80,80,80,40,20,
    17,90,25,71,10,65,25,78,31,45,95,89,16,30,10,100,15,89,48,30,50,15,67,88,
    37,60,75,53,100,42,95,55,100,85,100,100,87,100,89,94,100,100,100,94,94,
    26,95,5,30,58,100,87,10,25,65,100,94,94,94,95,95,27,50,15,0,100,95,95,30,
    100,90,31,42,88,15,100,90,95,84,95,21,25,40,85,100,21,30,30,30,95,11,10,
    5,89,75,95,75,35,95,78,95,94,94,35,40,25,94,18,20,90,10,100,78,57,67,100,
    100,94,100,100,100,94,94,25,65,100,100,100,100,35,52,74,89,24,50,44,40,
    95,84,21,21,85,95,91,94,89,85,20,84,20,89,94,20,18,26,73,79,24,78,10,20,
    22,30,5,100,21,90,20,85,90,35,35,100,69,95,100,100,53,85,84,63,10,45,79,
    15,95,95,5,100,100,95,90,30,84,94,95,15,67,90,90,45,95,10,5,25,75,21,84,
    30,85,70,95,80,5,15,90,26,90,95,79,56,30,63,70,87,75,15,84,95,80,84,15,
    40,85,5,10,10,89,64,40,88,10,15,89,80,25,100,15,95,25,10,90,82,60,10,89,
    5,5,5,75,20,25,25,90,45,70,15,41,76,35,30,84,94,43,94,100,95,15,94,90,
    94,95,94,94,25,95,90,15,100,17,15)
id<-c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,
    29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,
    53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,
    77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,
    101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,
    119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,
    137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,
    155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,
    173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,
    191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,
    209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,
    227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,
    245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,
    263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,
    281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,
    299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,
    317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,
    335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,
    353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,
    371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,
    389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,
    407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,
    425,426,427,428,429,430,431,432,433)
ADA<-c(0,13,11,33,45,45,34,26,8,89,0,3,10,72,32,15,54,69,10,95,77,97,97,100,97,
    100,100,72,23,89,7,77,82,15,81,5,10,3,2,89,100,97,100,97,97,97,86,100,72,
    5,85,5,97,5,8,8,0,5,2,7,85,5,89,76,5,20,17,5,89,95,94,79,22,41,55,10,43,
    62,36,2,54,46,5,13,2,26,10,5,51,8,63,97,72,65,25,36,12,2,43,5,13,35,33,
    18,73,77,2,42,100,100,69,39,51,10,100,73,100,17,74,2,17,5,15,17,100,5,75,
    74,56,63,85,64,2,15,7,5,21,61,57,84,57,33,34,76,10,90,7,50,20,55,10,28,
    62,54,8,10,10,82,0,78,23,30,31,7,51,72,37,42,30,18,90,5,85,15,100,95,75,
    77,87,100,95,85,100,87,97,77,97,30,90,2,32,69,94,83,2,8,37,97,97,82,89,
    80,85,5,67,15,23,92,95,80,13,90,56,13,10,46,3,100,58,70,37,97,7,7,10,42,
    92,5,15,5,10,57,5,2,15,78,75,87,55,37,80,50,79,81,100,27,20,22,82,11,5,
    72,6,94,85,16,20,43,97,95,72,89,100,97,95,22,66,97,100,97,64,22,41,43,
    44,8,47,15,18,82,66,7,13,79,87,79,69,32,41,2,60,5,62,44,8,14,10,67,76,
    18,66,5,5,10,5,8,69,2,67,7,72,92,13,20,95,60,82,87,100,36,76,46,34,5,25,
    77,13,70,91,5,92,97,77,67,15,57,100,90,7,35,60,43,47,100,10,7,12,79,25,
    67,32,65,42,81,75,5,5,60,19,48,42,79,18,12,28,62,51,66,10,44,97,35,44,5,
    14,60,2,2,5,76,47,26,71,2,7,60,65,12,100,5,92,3,2,59,58,40,7,55,2,5,5,
    62,5,13,5,41,8,54,0,10,66,10,33,82,81,23,79,70,97,17,54,77,76,84,60,100,
    37,75,86,17,89,5,15)
Congress<-cbind(state,district,party,DemProb,RepProb,armed,appropriations,budget,
        edlabor,foreign,interior,public,smallbus,agric,aging,asc,bipac,
        ccus,cope,ibt,mnpl,rlea,nea,lcv,pccw,nfu,ncsc,id,ADA)
        

########################################################################################################

#the following are the commands to replicate the last column in Table 1 of Groseclose 1994
comcomp1<-function(nreps,floorscore,commscore,commsize,IG){
    counter<-0
    committee<-rnorm(nreps)
        for (i in 1:nreps){
            committee[i]<-median(sample(IG,commsize,replace=FALSE))
            if(floorscore<=commscore&&committee[i]>=commscore){counter<-counter+1}
            else if(floorscore>commscore&&committee[i]<=commscore){counter<-counter+1}
            proprepcom<-counter/nreps
            }
    print(proprepcom)
}


comcomp1(20000,median(Congress[,16]),median(Congress[armed==1,16]),length(Congress[armed==1,1]),asc)
comcomp1(20000,median(Congress[,17]),median(Congress[appropriations==1,17]),length(Congress[appropriations==1,1]),bipac)
comcomp1(20000,median(Congress[,18]),median(Congress[appropriations==1,18]),length(Congress[appropriations==1,1]),ccus)
comcomp1(20000,median(Congress[,17]),median(Congress[budget==1,17]),length(Congress[budget==1,1]),bipac)
comcomp1(20000,median(Congress[,18]),median(Congress[budget==1,18]),length(Congress[budget==1,1]),ccus)
comcomp1(20000,median(Congress[,19]),median(Congress[edlabor==1,19]),length(Congress[edlabor==1,1]),cope)
comcomp1(20000,median(Congress[,20]),median(Congress[edlabor==1,20]),length(Congress[edlabor==1,1]),ibt)
comcomp1(20000,median(Congress[,21]),median(Congress[edlabor==1,21]),length(Congress[edlabor==1,1]),mnpl)
comcomp1(20000,median(Congress[,22]),median(Congress[edlabor==1,22]),length(Congress[edlabor==1,1]),rlea)
comcomp1(20000,median(Congress[,23]),median(Congress[edlabor==1,23]),length(Congress[edlabor==1,1]),nea)
comcomp1(20000,median(Congress[,16]),median(Congress[foreign==1,16]),length(Congress[foreign==1,1]),asc)
comcomp1(20000,median(Congress[,18]),median(Congress[interior==1,18]),length(Congress[interior==1,1]),ccus)
comcomp1(20000,median(Congress[,24]),median(Congress[interior==1,24]),length(Congress[interior==1,1]),lcv)
comcomp1(20000,median(Congress[,25]),median(Congress[interior==1,25]),length(Congress[interior==1,1]),pccw)
comcomp1(20000,median(Congress[,18]),median(Congress[public==1,18]),length(Congress[public==1,1]),ccus)
comcomp1(20000,median(Congress[,24]),median(Congress[public==1,24]),length(Congress[public==1,1]),lcv)
comcomp1(20000,median(Congress[,25]),median(Congress[public==1,25]),length(Congress[public==1,1]),pccw)
comcomp1(20000,median(Congress[,22]),median(Congress[public==1,22]),length(Congress[public==1,1]),rlea)
comcomp1(20000,median(Congress[,17]),median(Congress[smallbus==1,17]),length(Congress[smallbus==1,1]),bipac)
comcomp1(20000,median(Congress[,26]),median(Congress[agric==1,26]),length(Congress[agric==1,1]),nfu)
comcomp1(20000,median(Congress[,27]),median(Congress[aging==1,27]),length(Congress[aging==1,1]),ncsc)



#this function is Table 1 conditional on having to be a majority-rules committee
comcomp2<-function(nreps,floorscore,commscore,commsize,IG)  {
    counter<-0
    committee<-0
    Demprop<-0
    allseen<-0
    MajorityCount<-0
while((allseen!=nreps)){
            committeerow<-sample(row(Congress),commsize,replace=FALSE)
            Demprop<-mean(Congress[committeerow,3])
            committee<-median(Congress[committeerow,IG])
            if(floorscore<=commscore&&committee>=commscore&&Demprop>.5){counter<-counter+1}
                    else if(floorscore>commscore&&committee<=commscore&&Demprop>.5){counter<-counter+1}
            if(Demprop>.5){MajorityCount<-MajorityCount+1}
                    proprepcom<-counter/nreps
                    if(MajorityCount==nreps){allseen<-nreps}
    }
print(proprepcom)
}

comcomp2(20000,median(Congress[,16]),median(Congress[armed==1,16]),length(Congress[armed==1,1]),"asc")
comcomp2(20000,median(Congress[,17]),median(Congress[appropriations==1,17]),length(Congress[appropriations==1,1]),"bipac")
comcomp2(20000,median(Congress[,18]),median(Congress[appropriations==1,18]),length(Congress[appropriations==1,1]),"ccus")
comcomp2(20000,median(Congress[,17]),median(Congress[budget==1,17]),length(Congress[budget==1,1]),"bipac")
comcomp2(20000,median(Congress[,18]),median(Congress[budget==1,18]),length(Congress[budget==1,1]),"ccus")
comcomp2(20000,median(Congress[,19]),median(Congress[edlabor==1,19]),length(Congress[edlabor==1,1]),"cope")
comcomp2(20000,median(Congress[,20]),median(Congress[edlabor==1,20]),length(Congress[edlabor==1,1]),"ibt")
comcomp2(20000,median(Congress[,21]),median(Congress[edlabor==1,21]),length(Congress[edlabor==1,1]),"mnpl")
comcomp2(20000,median(Congress[,22]),median(Congress[edlabor==1,22]),length(Congress[edlabor==1,1]),"rlea")
comcomp2(20000,median(Congress[,23]),median(Congress[edlabor==1,23]),length(Congress[edlabor==1,1]),"nea")
comcomp2(20000,median(Congress[,16]),median(Congress[foreign==1,16]),length(Congress[foreign==1,1]),"asc")
comcomp2(20000,median(Congress[,18]),median(Congress[interior==1,18]),length(Congress[interior==1,1]),"ccus")
comcomp2(20000,median(Congress[,24]),median(Congress[interior==1,24]),length(Congress[interior==1,1]),"lcv")
comcomp2(20000,median(Congress[,25]),median(Congress[interior==1,25]),length(Congress[interior==1,1]),"pccw")
comcomp2(20000,median(Congress[,18]),median(Congress[public==1,18]),length(Congress[public==1,1]),"ccus")
comcomp2(20000,median(Congress[,24]),median(Congress[public==1,24]),length(Congress[public==1,1]),"lcv")
comcomp2(20000,median(Congress[,25]),median(Congress[public==1,25]),length(Congress[public==1,1]),"pccw")
comcomp2(20000,median(Congress[,22]),median(Congress[public==1,22]),length(Congress[public==1,1]),"rlea")
comcomp2(20000,median(Congress[,17]),median(Congress[smallbus==1,17]),length(Congress[smallbus==1,1]),"bipac")
comcomp2(20000,median(Congress[,26]),median(Congress[agric==1,26]),length(Congress[agric==1,1]),"nfu")
comcomp2(20000,median(Congress[,27]),median(Congress[aging==1,27]),length(Congress[aging==1,1]),"ncsc")




#this function is Table 1 conditional on exact party proportion to that which really exists
comcomp3<-function(nreps,floorscore,commscore,Demsize,Repsize,IG)   {
    counter<-0
    committee<-rnorm(nreps)
    committeecreate<-rnorm(nreps)
    DemContingent<-rnorm(nreps)
    RepContingent<-rnorm(nreps)
        for(i in 1:nreps){
            committee[i]<-median(committeecreate<-c((DemContingent<-sample(IG,Demsize,replace=FALSE,prob=DemProb)),(RepContingent<-sample(IG,Repsize,replace=FALSE, prob=RepProb))))
            if(floorscore<=commscore&&committee[i]>=commscore){counter<-counter+1}
            else if(floorscore>commscore&&committee[i]<=commscore){counter<-counter+1}
            proprepcom<-counter/nreps
            }
    print(proprepcom)
}
comcomp3(20000,median(Congress[,16]),median(Congress[armed==1,16]),length(Congress[armed==1&party==1,1]),length(Congress[armed==1&party==0,1]),asc)
comcomp3(20000,median(Congress[,17]),median(Congress[appropriations==1,17]),length(Congress[appropriations==1&party==1,1]),length(Congress[appropriations==1&party==0,1]),bipac)
comcomp3(20000,median(Congress[,18]),median(Congress[appropriations==1,18]),length(Congress[appropriations==1&party==1,1]),length(Congress[appropriations==1&party==0,1]),ccus)
comcomp3(20000,median(Congress[,17]),median(Congress[budget==1,17]),length(Congress[budget==1&party==1,1]),length(Congress[budget==1&party==0,1]),bipac)
comcomp3(20000,median(Congress[,18]),median(Congress[budget==1,18]),length(Congress[budget==1&party==1,1]),length(Congress[budget==1&party==0,1]),ccus)
comcomp3(20000,median(Congress[,19]),median(Congress[edlabor==1,19]),length(Congress[edlabor==1&party==1,1]),length(Congress[edlabor==1&party==0,1]),cope)
comcomp3(20000,median(Congress[,20]),median(Congress[edlabor==1,20]),length(Congress[edlabor==1&party==1,1]),length(Congress[edlabor==1&party==0,1]),ibt)
comcomp3(20000,median(Congress[,21]),median(Congress[edlabor==1,21]),length(Congress[edlabor==1&party==1,1]),length(Congress[edlabor==1&party==0,1]),mnpl)
comcomp3(20000,median(Congress[,22]),median(Congress[edlabor==1,22]),length(Congress[edlabor==1&party==1,1]),length(Congress[edlabor==1&party==0,1]),rlea)
comcomp3(20000,median(Congress[,23]),median(Congress[edlabor==1,23]),length(Congress[edlabor==1&party==1,1]),length(Congress[edlabor==1&party==0,1]),nea)
comcomp3(20000,median(Congress[,16]),median(Congress[foreign==1,16]),length(Congress[foreign==1&party==1,1]),length(Congress[foreign==1&party==0,1]),asc)
comcomp3(20000,median(Congress[,18]),median(Congress[interior==1,18]),length(Congress[interior==1&party==1,1]),length(Congress[interior==1&party==0,1]),ccus)
comcomp3(20000,median(Congress[,24]),median(Congress[interior==1,24]),length(Congress[interior==1&party==1,1]),length(Congress[interior==1&party==0,1]),lcv)
comcomp3(20000,median(Congress[,25]),median(Congress[interior==1,25]),length(Congress[interior==1&party==1,1]),length(Congress[interior==1&party==0,1]),pccw)
comcomp3(20000,median(Congress[,18]),median(Congress[public==1,18]),length(Congress[public==1&party==1,1]),length(Congress[public==1&party==0,1]),ccus)
comcomp3(20000,median(Congress[,24]),median(Congress[public==1,24]),length(Congress[public==1&party==1,1]),length(Congress[public==1&party==0,1]),lcv)
comcomp3(20000,median(Congress[,25]),median(Congress[public==1,25]),length(Congress[public==1&party==1,1]),length(Congress[public==1&party==0,1]),pccw)
comcomp3(20000,median(Congress[,22]),median(Congress[public==1,22]),length(Congress[public==1&party==1,1]),length(Congress[public==1&party==0,1]),rlea)
comcomp3(20000,median(Congress[,17]),median(Congress[smallbus==1,17]),length(Congress[smallbus==1&party==1,1]),length(Congress[smallbus==1&party==0,1]),bipac)
comcomp3(20000,median(Congress[,26]),median(Congress[agric==1,26]),length(Congress[agric==1&party==1,1]),length(Congress[agric==1&party==0,1]),nfu)
comcomp3(20000,median(Congress[,27]),median(Congress[aging==1,27]),length(Congress[aging==1&party==1,1]),length(Congress[aging==1&party==0,1]),ncsc)

########################################################################################################

#the following functions relate to the "opposing outlier" hypothesis tested by Groseclose
#the following function is Democratic outlier not conditional on anything
#Note: there doesn't have to be any conditions with this hypothesis


comcomp4<-function(nreps,floorscore,partyscore,commscore,commsize,IG)   {
    counter<-0
    committee<-rnorm(nreps)
        for (i in 1:nreps){
        committee[i]<-median(sample(IG,commsize,replace=FALSE,prob=DemProb))
        if(floorscore<partyscore&&committee[i]>=commscore){counter<-counter+1}
        else if(floorscore>partyscore&&committee[i]<=commscore){counter<-counter+1}
        proprepcom<-counter/nreps
        }
    print(proprepcom)
}       
comcomp4(20000,median(Congress[,16]),median(Congress[party==1,16]),median(Congress[armed==1&party==1,16]),length(Congress[armed==1&party==1,1]),asc)
comcomp4(20000,median(Congress[,17]),median(Congress[party==1,17]),median(Congress[appropriations==1&party==1,17]),length(Congress[appropriations==1&party==1,1]),bipac)
comcomp4(20000,median(Congress[,18]),median(Congress[party==1,18]),median(Congress[appropriations==1&party==1,18]),length(Congress[appropriations==1&party==1,1]),ccus)
comcomp4(20000,median(Congress[,17]),median(Congress[party==1,17]),median(Congress[budget==1&party==1,17]),length(Congress[budget==1&party==1,1]),bipac)
comcomp4(20000,median(Congress[,18]),median(Congress[party==1,18]),median(Congress[budget==1&party==1,18]),length(Congress[budget==1&party==1,1]),ccus)
comcomp4(20000,median(Congress[,19]),median(Congress[party==1,19]),median(Congress[edlabor==1&party==1,19]),length(Congress[edlabor==1&party==1,1]),cope)
comcomp4(20000,median(Congress[,20]),median(Congress[party==1,20]),median(Congress[edlabor==1&party==1,20]),length(Congress[edlabor==1&party==1,1]),ibt)
comcomp4(20000,median(Congress[,21]),median(Congress[party==1,21]),median(Congress[edlabor==1&party==1,21]),length(Congress[edlabor==1&party==1,1]),mnpl)
comcomp4(20000,median(Congress[,22]),median(Congress[party==1,22]),median(Congress[edlabor==1&party==1,22]),length(Congress[edlabor==1&party==1,1]),rlea)
comcomp4(20000,median(Congress[,23]),median(Congress[party==1,23]),median(Congress[edlabor==1&party==1,23]),length(Congress[edlabor==1&party==1,1]),nea)
comcomp4(20000,median(Congress[,16]),median(Congress[party==1,16]),median(Congress[foreign==1&party==1,16]),length(Congress[foreign==1&party==1,1]),asc)
comcomp4(20000,median(Congress[,18]),median(Congress[party==1,18]),median(Congress[interior==1&party==1,18]),length(Congress[interior==1&party==1,1]),ccus)
comcomp4(20000,median(Congress[,24]),median(Congress[party==1,24]),median(Congress[interior==1&party==1,24]),length(Congress[interior==1&party==1,1]),lcv)
comcomp4(20000,median(Congress[,25]),median(Congress[party==1,25]),median(Congress[interior==1&party==1,25]),length(Congress[interior==1&party==1,1]),pccw)
comcomp4(20000,median(Congress[,18]),median(Congress[party==1,18]),median(Congress[public==1&party==1,18]),length(Congress[public==1&party==1,1]),ccus)
comcomp4(20000,median(Congress[,24]),median(Congress[party==1,24]),median(Congress[public==1&party==1,24]),length(Congress[public==1&party==1,1]),lcv)
comcomp4(20000,median(Congress[,25]),median(Congress[party==1,25]),median(Congress[public==1&party==1,25]),length(Congress[public==1&party==1,1]),pccw)
comcomp4(20000,median(Congress[,22]),median(Congress[party==1,22]),median(Congress[public==1&party==1,22]),length(Congress[public==1&party==1,1]),rlea)
comcomp4(20000,median(Congress[,17]),median(Congress[party==1,17]),median(Congress[smallbus==1&party==1,17]),length(Congress[smallbus==1&party==1,1]),bipac)
comcomp4(20000,median(Congress[,26]),median(Congress[party==1,26]),median(Congress[agric==1&party==1,26]),length(Congress[agric==1&party==1,1]),nfu)
comcomp4(20000,median(Congress[,27]),median(Congress[party==1,27]),median(Congress[aging==1&party==1,27]),length(Congress[aging==1&party==1,1]),ncsc)



#the following function is Republican outlier not conditional on anything

comcomp5<-function(nreps,floorscore,partyscore,commscore,commsize,IG)   {
    counter<-0
    committee<-rnorm(nreps)
        for (i in 1:nreps){
        committee[i]<-median(sample(IG,commsize,replace=FALSE,prob=RepProb))
        if(floorscore<partyscore&&committee[i]>=commscore){counter<-counter+1}
        else if(floorscore>partyscore&&committee[i]<=commscore){counter<-counter+1}
        proprepcom<-counter/nreps
        }
    print(proprepcom)
}
        
comcomp5(20000,median(Congress[,16]),median(Congress[party==0,16]),median(Congress[armed==1&party==0,16]),length(Congress[armed==1&party==0,1]),asc)
comcomp5(20000,median(Congress[,17]),median(Congress[party==0,17]),median(Congress[appropriations==1&party==0,17]),length(Congress[appropriations==1&party==0,1]),bipac)
comcomp5(20000,median(Congress[,18]),median(Congress[party==0,18]),median(Congress[appropriations==1&party==0,18]),length(Congress[appropriations==1&party==0,1]),ccus)
comcomp5(20000,median(Congress[,17]),median(Congress[party==0,17]),median(Congress[budget==1&party==0,17]),length(Congress[budget==1&party==0,1]),bipac)
comcomp5(20000,median(Congress[,18]),median(Congress[party==0,18]),median(Congress[budget==1&party==0,18]),length(Congress[budget==1&party==0,1]),ccus)
comcomp5(20000,median(Congress[,19]),median(Congress[party==0,19]),median(Congress[edlabor==1&party==0,19]),length(Congress[edlabor==1&party==0,1]),cope)
comcomp5(20000,median(Congress[,20]),median(Congress[party==0,20]),median(Congress[edlabor==1&party==0,20]),length(Congress[edlabor==1&party==0,1]),ibt)
comcomp5(20000,median(Congress[,21]),median(Congress[party==0,21]),median(Congress[edlabor==1&party==0,21]),length(Congress[edlabor==1&party==0,1]),mnpl)
comcomp5(20000,median(Congress[,22]),median(Congress[party==0,22]),median(Congress[edlabor==1&party==0,22]),length(Congress[edlabor==1&party==0,1]),rlea)
comcomp5(20000,median(Congress[,23]),median(Congress[party==0,23]),median(Congress[edlabor==1&party==0,23]),length(Congress[edlabor==1&party==0,1]),nea)
comcomp5(20000,median(Congress[,16]),median(Congress[party==0,16]),median(Congress[foreign==1&party==0,16]),length(Congress[foreign==1&party==0,1]),asc)
comcomp5(20000,median(Congress[,18]),median(Congress[party==0,18]),median(Congress[interior==1&party==0,18]),length(Congress[interior==1&party==0,1]),ccus)
comcomp5(20000,median(Congress[,24]),median(Congress[party==0,24]),median(Congress[interior==1&party==0,24]),length(Congress[interior==1&party==0,1]),lcv)
comcomp5(20000,median(Congress[,25]),median(Congress[party==0,25]),median(Congress[interior==1&party==0,25]),length(Congress[interior==1&party==0,1]),pccw)
comcomp5(20000,median(Congress[,18]),median(Congress[party==0,18]),median(Congress[public==1&party==0,18]),length(Congress[public==1&party==0,1]),ccus)
comcomp5(20000,median(Congress[,24]),median(Congress[party==0,24]),median(Congress[public==1&party==0,24]),length(Congress[public==1&party==0,1]),lcv)
comcomp5(20000,median(Congress[,25]),median(Congress[party==0,25]),median(Congress[public==1&party==0,25]),length(Congress[public==1&party==0,1]),pccw)
comcomp5(20000,median(Congress[,22]),median(Congress[party==0,22]),median(Congress[public==1&party==0,22]),length(Congress[public==1&party==0,1]),rlea)
comcomp5(20000,median(Congress[,17]),median(Congress[party==0,17]),median(Congress[smallbus==1&party==0,17]),length(Congress[smallbus==1&party==0,1]),bipac)
comcomp5(20000,median(Congress[,26]),median(Congress[party==0,26]),median(Congress[agric==1&party==0,26]),length(Congress[agric==1&party==0,1]),nfu)
comcomp5(20000,median(Congress[,27]),median(Congress[party==0,27]),median(Congress[aging==1&party==0,27]),length(Congress[aging==1&party==0,1]),ncsc)


########################################################################################################

#the following does the representative committee hypothesis (Table 6)

comcomp6<-function(nreps,floorscore,commscore,commsize,IG)  {
    counter<-0
    committee<-rnorm(nreps)
    proprepcom<-0
         for (i in 1:nreps)      {
                    committee[i]<-median(sample(IG,commsize,replace=FALSE))
                    }
                    if(commscore>median(committee)){proprepcom<-2*((length(committee[committee<=commscore])/nreps)-.5)}
                    else if(commscore==median(committee)){proprepcom<-(length(committee[committee==commscore])/nreps)}
                    else if(commscore<median(committee)){proprepcom<-2*(.5-(1-(length(committee[committee>=commscore])/nreps)))}
    print(median(committee))
    print(floorscore)
    print(commscore)
    print(proprepcom)
}

comcomp6(20000,median(Congress[,16]),median(Congress[armed==1,16]),length(Congress[armed==1,1]),asc)
comcomp6(20000,median(Congress[,17]),median(Congress[appropriations==1,17]),length(Congress[appropriations==1,1]),bipac)
comcomp6(20000,median(Congress[,18]),median(Congress[appropriations==1,18]),length(Congress[appropriations==1,1]),ccus)
comcomp6(20000,median(Congress[,17]),median(Congress[budget==1,17]),length(Congress[budget==1,1]),bipac)
comcomp6(20000,median(Congress[,18]),median(Congress[budget==1,18]),length(Congress[budget==1,1]),ccus)
comcomp6(20000,median(Congress[,19]),median(Congress[edlabor==1,19]),length(Congress[edlabor==1,1]),cope)
comcomp6(20000,median(Congress[,20]),median(Congress[edlabor==1,20]),length(Congress[edlabor==1,1]),ibt)
comcomp6(20000,median(Congress[,21]),median(Congress[edlabor==1,21]),length(Congress[edlabor==1,1]),mnpl)
comcomp6(20000,median(Congress[,22]),median(Congress[edlabor==1,22]),length(Congress[edlabor==1,1]),rlea)
comcomp6(20000,median(Congress[,23]),median(Congress[edlabor==1,23]),length(Congress[edlabor==1,1]),nea)
comcomp6(20000,median(Congress[,16]),median(Congress[foreign==1,16]),length(Congress[foreign==1,1]),asc)
comcomp6(20000,median(Congress[,18]),median(Congress[interior==1,18]),length(Congress[interior==1,1]),ccus)
comcomp6(20000,median(Congress[,24]),median(Congress[interior==1,24]),length(Congress[interior==1,1]),lcv)
comcomp6(20000,median(Congress[,25]),median(Congress[interior==1,25]),length(Congress[interior==1,1]),pccw)
comcomp6(20000,median(Congress[,18]),median(Congress[public==1,18]),length(Congress[public==1,1]),ccus)
comcomp6(20000,median(Congress[,24]),median(Congress[public==1,24]),length(Congress[public==1,1]),lcv)
comcomp6(20000,median(Congress[,25]),median(Congress[public==1,25]),length(Congress[public==1,1]),pccw)
comcomp6(20000,median(Congress[,22]),median(Congress[public==1,22]),length(Congress[public==1,1]),rlea)
comcomp6(20000,median(Congress[,17]),median(Congress[smallbus==1,17]),length(Congress[smallbus==1,1]),bipac)
comcomp6(20000,median(Congress[,26]),median(Congress[agric==1,26]),length(Congress[agric==1,1]),nfu)
comcomp6(20000,median(Congress[,27]),median(Congress[aging==1,27]),length(Congress[aging==1,1]),ncsc)


#below is a function  for finding the proportion of committees that would fall in a range by chance conditional on majority-rules

comcomp7<-function(nreps,floorscore,commscore,commsize,IG)  {
    committee<-matrix(0, nreps, 1)
    counter<-0
    Demprop<-0
    allseen<-0
    i <-0
    DemCount<-0
    proprepcom<-0
while((allseen!=nreps)){
            committeerow<-sample(row(Congress),commsize, replace=FALSE)
            Demprop<-mean(Congress[committeerow,3])
            if(Demprop>.5){i<-i+1}
            if (Demprop>.5){committee[i,1]<-median(Congress[committeerow,IG])}
                    if(i==nreps){allseen<-nreps}
                    CongSim<-committee
    }
          if(commscore>median(committee)){proprepcom<-2*((length(CongSim[CongSim<=commscore])/nreps)-.5)}
                    else if(commscore==median(committee)){proprepcom<-(length(CongSim[CongSim==commscore])/nreps)}
                    else if(commscore<median(committee)){proprepcom<-2*(.5-(1-(length(CongSim[CongSim>=commscore])/nreps)))}         
    print(median(committee))
    print(floorscore)
    print(commscore)
    print(proprepcom)
}

comcomp7(20000,median(Congress[,16]),median(Congress[armed==1,16]),length(Congress[armed==1,1]),"asc")
comcomp7(20000,median(Congress[,17]),median(Congress[appropriations==1,17]),length(Congress[appropriations==1,1]),"bipac")
comcomp7(20000,median(Congress[,18]),median(Congress[appropriations==1,18]),length(Congress[appropriations==1,1]),"ccus")
comcomp7(20000,median(Congress[,17]),median(Congress[budget==1,17]),length(Congress[budget==1,1]),"bipac")
comcomp7(20000,median(Congress[,18]),median(Congress[budget==1,18]),length(Congress[budget==1,1]),"ccus")
comcomp7(20000,median(Congress[,19]),median(Congress[edlabor==1,19]),length(Congress[edlabor==1,1]),"cope")
comcomp7(20000,median(Congress[,20]),median(Congress[edlabor==1,20]),length(Congress[edlabor==1,1]),"ibt")
comcomp7(20000,median(Congress[,21]),median(Congress[edlabor==1,21]),length(Congress[edlabor==1,1]),"mnpl")
comcomp7(20000,median(Congress[,22]),median(Congress[edlabor==1,22]),length(Congress[edlabor==1,1]),"rlea")
comcomp7(20000,median(Congress[,23]),median(Congress[edlabor==1,23]),length(Congress[edlabor==1,1]),"nea")
comcomp7(20000,median(Congress[,16]),median(Congress[foreign==1,16]),length(Congress[foreign==1,1]),"asc")
comcomp7(20000,median(Congress[,18]),median(Congress[interior==1,18]),length(Congress[interior==1,1]),"ccus")
comcomp7(20000,median(Congress[,24]),median(Congress[interior==1,24]),length(Congress[interior==1,1]),"lcv")
comcomp7(20000,median(Congress[,25]),median(Congress[interior==1,25]),length(Congress[interior==1,1]),"pccw")
comcomp7(20000,median(Congress[,18]),median(Congress[public==1,18]),length(Congress[public==1,1]),"ccus")
comcomp7(20000,median(Congress[,24]),median(Congress[public==1,24]),length(Congress[public==1,1]),"lcv")
comcomp7(20000,median(Congress[,25]),median(Congress[public==1,25]),length(Congress[public==1,1]),"pccw")
comcomp7(20000,median(Congress[,22]),median(Congress[public==1,22]),length(Congress[public==1,1]),"rlea")
comcomp7(20000,median(Congress[,17]),median(Congress[smallbus==1,17]),length(Congress[smallbus==1,1]),"bipac")
comcomp7(20000,median(Congress[,26]),median(Congress[agric==1,26]),length(Congress[agric==1,1]),"nfu")
comcomp7(20000,median(Congress[,27]),median(Congress[aging==1,27]),length(Congress[aging==1,1]),"ncsc")



comcomp8<-function(nreps,floorscore,commscore,Demsize,Repsize,IG)   {
    counter<-0
    committee<-rnorm(nreps)
    committeecreate<-rnorm(nreps)
    DemContingent<-rnorm(nreps)
    RepContingent<-rnorm(nreps)
         for (i in 1:nreps)      {
            committee[i]<-median(committeecreate<-c((DemContingent<-sample(IG,Demsize,replace=FALSE,prob=DemProb)),(RepContingent<-sample(IG,Repsize,replace=FALSE,prob=RepProb))))
                    }
                    if(commscore>median(committee)){proprepcom<-2*((length(committee[committee<=commscore])/nreps)-.5)}
                    else if(commscore==median(committee)){proprepcom<-(length(committee[committee==commscore])/nreps)}
                    else if(commscore<median(committee)){proprepcom<-2*((length(committee[committee>=commscore])/nreps)-.5)}
    print(median(committee))
    print(floorscore)
    print(commscore)
    print(proprepcom)
}

comcomp8(20000,median(Congress[,16]),median(Congress[armed==1,16]),length(Congress[armed==1&party==1,1]),length(Congress[armed==1&party==0,1]),asc)
comcomp8(20000,median(Congress[,17]),median(Congress[appropriations==1,17]),length(Congress[appropriations==1&party==1,1]),length(Congress[appropriations==1&party==0,1]),bipac)
comcomp8(20000,median(Congress[,18]),median(Congress[appropriations==1,18]),length(Congress[appropriations==1&party==1,1]),length(Congress[appropriations==1&party==0,1]),ccus)
comcomp8(20000,median(Congress[,17]),median(Congress[budget==1,17]),length(Congress[budget==1&party==1,1]),length(Congress[budget==1&party==0,1]),bipac)
comcomp8(20000,median(Congress[,18]),median(Congress[budget==1,18]),length(Congress[budget==1&party==1,1]),length(Congress[budget==1&party==0,1]),ccus)
comcomp8(20000,median(Congress[,19]),median(Congress[edlabor==1,19]),length(Congress[edlabor==1&party==1,1]),length(Congress[edlabor==1&party==0,1]),cope)
comcomp8(20000,median(Congress[,20]),median(Congress[edlabor==1,20]),length(Congress[edlabor==1&party==1,1]),length(Congress[edlabor==1&party==0,1]),ibt)
comcomp8(20000,median(Congress[,21]),median(Congress[edlabor==1,21]),length(Congress[edlabor==1&party==1,1]),length(Congress[edlabor==1&party==0,1]),mnpl)
comcomp8(20000,median(Congress[,22]),median(Congress[edlabor==1,22]),length(Congress[edlabor==1&party==1,1]),length(Congress[edlabor==1&party==0,1]),rlea)
comcomp8(20000,median(Congress[,23]),median(Congress[edlabor==1,23]),length(Congress[edlabor==1&party==1,1]),length(Congress[edlabor==1&party==0,1]),nea)
comcomp8(20000,median(Congress[,16]),median(Congress[foreign==1,16]),length(Congress[foreign==1&party==1,1]),length(Congress[foreign==1&party==0,1]),asc)
comcomp8(20000,median(Congress[,18]),median(Congress[interior==1,18]),length(Congress[interior==1&party==1,1]),length(Congress[interior==1&party==0,1]),ccus)
comcomp8(20000,median(Congress[,24]),median(Congress[interior==1,24]),length(Congress[interior==1&party==1,1]),length(Congress[interior==1&party==0,1]),lcv)
comcomp8(20000,median(Congress[,25]),median(Congress[interior==1,25]),length(Congress[interior==1&party==1,1]),length(Congress[interior==1&party==0,1]),pccw)
comcomp8(20000,median(Congress[,18]),median(Congress[public==1,18]),length(Congress[public==1&party==1,1]),length(Congress[public==1&party==0,1]),ccus)
comcomp8(20000,median(Congress[,24]),median(Congress[public==1,24]),length(Congress[public==1&party==1,1]),length(Congress[public==1&party==0,1]),lcv)
comcomp8(20000,median(Congress[,25]),median(Congress[public==1,25]),length(Congress[public==1&party==1,1]),length(Congress[public==1&party==0,1]),pccw)
comcomp8(20000,median(Congress[,22]),median(Congress[public==1,22]),length(Congress[public==1&party==1,1]),length(Congress[public==1&party==0,1]),rlea)
comcomp8(20000,median(Congress[,17]),median(Congress[smallbus==1,17]),length(Congress[smallbus==1&party==1,1]),length(Congress[smallbus==1&party==0,1]),bipac)
comcomp8(20000,median(Congress[,26]),median(Congress[agric==1,26]),length(Congress[agric==1&party==1,1]),length(Congress[agric==1&party==0,1]),nfu)
comcomp8(20000,median(Congress[,27]),median(Congress[aging==1,27]),length(Congress[aging==1&party==1,1]),length(Congress[aging==1&party==0,1]),ncsc)


########################################################################################################

#the following does the Democratic representative committee hypothesis (Table 7)

#### 99th 

ADA.99 <- read.table("ADA99th.txt", header=TRUE)

attach(ADA.99)

ADA.99.1 <- na.omit(ADA.99)
remove(ADA.99)
attach(ADA.99.1)

ADA.99.1[sample(1:10),1:3]

comcomp9<-function(nreps,Demfloorscore,Demcommscore,Demcommsize,IG)    {
    counter<-0
    committee<-rnorm(nreps)
    proprepcom<-0
         for (i in 1:nreps)      {
                    committee[i]<-median(sample(ADA85,Demcommsize,replace=FALSE, prob=DemProb))
                    }
                    if(Demcommscore>Demfloorscore){proprepcom<-2*((length(committee[committee<=Demcommscore])/nreps)-.5)}
                    else if(Demcommscore==Demfloorscore){proprepcom<-(length(committee[committee==Demcommscore])/nreps)}
                    else if(Demcommscore<Demfloorscore){proprepcom<-2*((length(committee[committee>=Demcommscore])/nreps)-.5)}
    print(proprepcom)
    print(median(committee))
    print(Demfloorscore)
    print(Demcommscore)
}

comcomp9(20000,median(ADA.99.1[DemProb==1,"ADA85"]),median(ADA.99.1[Appropriations==1&DemProb==1,"ADA85"]),length(ADA.99.1[Appropriations==1&DemProb==1,1]),ADA85)
comcomp9(20000,median(ADA.99.1[DemProb==1,"ADA85"]),median(ADA.99.1[Energy.and.Commerce==1&DemProb==1,"ADA85"]),length(ADA.99.1[Energy.and.Commerce==1&DemProb==1,1]),ADA85)
comcomp9(20000,median(ADA.99.1[DemProb==1,"ADA85"]),median(ADA.99.1[Rules==1&DemProb==1,"ADA85"]),length(ADA.99.1[Rules==1&DemProb==1,1]),ADA85)
comcomp9(20000,median(ADA.99.1[DemProb==1,"ADA85"]),median(ADA.99.1[Ways.and.Means==1&DemProb==1,"ADA85"]),length(ADA.99.1[Ways.and.Means==1&DemProb==1,1]),ADA85)
comcomp9(20000,median(ADA.99.1[DemProb==1,"ADA85"]),median(ADA.99.1[Science.and.Technology==1&DemProb==1,"ADA85"]),length(ADA.99.1[Science.and.Technology==1&DemProb==1,1]),ADA85)
comcomp9(20000,median(ADA.99.1[DemProb==1,"ADA85"]),median(ADA.99.1[Public.Works==1&DemProb==1,"ADA85"]),length(ADA.99.1[Public.Works==1&DemProb==1,1]),ADA85)
comcomp9(20000,median(ADA.99.1[DemProb==1,"ADA85"]),median(ADA.99.1[Post.Office==1&DemProb==1,"ADA85"]),length(ADA.99.1[Post.Office==1&DemProb==1,1]),ADA85)
comcomp9(20000,median(ADA.99.1[DemProb==1,"ADA85"]),median(ADA.99.1[Veteran.Affairs==1&DemProb==1,"ADA85"]),length(ADA.99.1[Veteran.Affairs==1&DemProb==1,1]),ADA85)
comcomp9(20000,median(ADA.99.1[DemProb==1,"ADA85"]),median(ADA.99.1[House.Administration==1&DemProb==1,"ADA85"]),length(ADA.99.1[House.Administration==1&DemProb==1,1]),ADA85)
comcomp9(20000,median(ADA.99.1[DemProb==1,"ADA85"]),median(ADA.99.1[Government.Operations==1&DemProb==1,"ADA85"]),length(ADA.99.1[Government.Operations==1&DemProb==1,1]),ADA85)

#Because the median of the medians always matches the median of the Demfloor, which makes sense since we are randomly selecting from them, 
#there are none of the problems associated with the conditioning for the representative committee hypothesis.

#########################################################################
#Update to this test with new data from Krehbiel
#the following does the Democratic representative committee hypothesis with the ADALegislate scores instead

#### 99th 

ADA.99 <- read.table("ADA99thUpdate.txt", header=TRUE)

attach(ADA.99)

ADA.99.1 <- na.omit(ADA.99)
remove(ADA.99)
attach(ADA.99.1)

ADA.99.1[sample(1:10),1:3]

comcomp9<-function(nreps,Demfloorscore,Demcommscore,Demcommsize,IG)    {
    counter<-0
    committee<-rnorm(nreps)
    proprepcom<-0
         for (i in 1:nreps)      {
                    committee[i]<-median(sample(ADA85.Legislate,Demcommsize,replace=FALSE, prob=DemProb))
                    }
                    if(Demcommscore>Demfloorscore){proprepcom<-2*((length(committee[committee<=Demcommscore])/nreps)-.5)}
                    else if(Demcommscore==Demfloorscore){proprepcom<-(length(committee[committee==Demcommscore])/nreps)}
                    else if(Demcommscore<Demfloorscore){proprepcom<-2*((length(committee[committee>=Demcommscore])/nreps)-.5)}
    print(proprepcom)
    print(median(committee))
    print(Demfloorscore)
    print(Demcommscore)
}

comcomp9(20000,median(ADA.99.1[DemProb==1,"ADA85.Legislate"]),median(ADA.99.1[Appropriations==1&DemProb==1,"ADA85.Legislate"]),length(ADA.99.1[Appropriations==1&DemProb==1,1]),ADA85.Legislate)
comcomp9(20000,median(ADA.99.1[DemProb==1,"ADA85.Legislate"]),median(ADA.99.1[Energy.and.Commerce==1&DemProb==1,"ADA85.Legislate"]),length(ADA.99.1[Energy.and.Commerce==1&DemProb==1,1]),ADA85.Legislate)
comcomp9(20000,median(ADA.99.1[DemProb==1,"ADA85.Legislate"]),median(ADA.99.1[Rules==1&DemProb==1,"ADA85.Legislate"]),length(ADA.99.1[Rules==1&DemProb==1,1]),ADA85.Legislate)
comcomp9(20000,median(ADA.99.1[DemProb==1,"ADA85.Legislate"]),median(ADA.99.1[Ways.and.Means==1&DemProb==1,"ADA85.Legislate"]),length(ADA.99.1[Ways.and.Means==1&DemProb==1,1]),ADA85.Legislate)
comcomp9(20000,median(ADA.99.1[DemProb==1,"ADA85.Legislate"]),median(ADA.99.1[Science.and.Technology==1&DemProb==1,"ADA85.Legislate"]),length(ADA.99.1[Science.and.Technology==1&DemProb==1,1]),ADA85.Legislate)
comcomp9(20000,median(ADA.99.1[DemProb==1,"ADA85.Legislate"]),median(ADA.99.1[Public.Works==1&DemProb==1,"ADA85.Legislate"]),length(ADA.99.1[Public.Works==1&DemProb==1,1]),ADA85.Legislate)
comcomp9(20000,median(ADA.99.1[DemProb==1,"ADA85.Legislate"]),median(ADA.99.1[Post.Office==1&DemProb==1,"ADA85.Legislate"]),length(ADA.99.1[Post.Office==1&DemProb==1,1]),ADA85.Legislate)
comcomp9(20000,median(ADA.99.1[DemProb==1,"ADA85.Legislate"]),median(ADA.99.1[Veteran.Affairs==1&DemProb==1,"ADA85.Legislate"]),length(ADA.99.1[Veteran.Affairs==1&DemProb==1,1]),ADA85.Legislate)
comcomp9(20000,median(ADA.99.1[DemProb==1,"ADA85.Legislate"]),median(ADA.99.1[House.Administration==1&DemProb==1,"ADA85.Legislate"]),length(ADA.99.1[House.Administration==1&DemProb==1,1]),ADA85.Legislate)
comcomp9(20000,median(ADA.99.1[DemProb==1,"ADA85.Legislate"]),median(ADA.99.1[Government.Operations==1&DemProb==1,"ADA85.Legislate"]),length(ADA.99.1[Government.Operations==1&DemProb==1,1]),ADA85.Legislate)


########################################################################################################
########################################################################################################
########################################################################################################
########################################################################################################

####105th CONGRESS

Congress.105 <- read.table("105Congress.txt", header=TRUE)
attach(Congress.105)

Congress.105[sample(1:10),1:3]

Congress.105 <- na.omit(Congress.105)

attach(Congress.105)

########################################################################################################

#There is an "NA" in nea and GA6 (Gingrich) is missing in all 4 IG scores

#the following are the commands to extend the last column in Table 1 in Groseclose(1994) to the 105th Congress


comcomp1a<-function(nreps,floorscore,commscore,commsize,IG){
    counter<-0
    committee<-rnorm(nreps)
        for (i in 1:nreps){
            committee[i]<-median(sample(IG,commsize,replace=FALSE))
            if(floorscore<=commscore&&committee[i]>=commscore){counter<-counter+1}
            else if(floorscore>commscore&&committee[i]<=commscore){counter<-counter+1}
            proprepcom<-counter/nreps
            }
    print(summary(committee))
    print(median(committee))
    print(floorscore)
    print(commscore)
    print(proprepcom)
}

comcomp1a(20000,median(Congress.105[,25]),median(Congress.105[Appropriations==1,25]),length(Congress.105[Appropriations==1,1]),ccus)
comcomp1a(20000,median(Congress.105[,25]),median(Congress.105[Budget==1,25]),length(Congress.105[Budget==1,1]),ccus)
comcomp1a(20000,median(Congress.105[,26]),median(Congress.105[Education.and.the.Workplace==1,26]),length(Congress.105[Education.and.the.Workplace==1,1]),cope)
comcomp1a(20000,median(Congress.105[,27]),median(Congress.105[Education.and.the.Workplace==1,27]),length(Congress.105[Education.and.the.Workplace==1,1]),nea)
comcomp1a(20000,median(Congress.105[,25]),median(Congress.105[Resources==1,25]),length(Congress.105[Resources==1,1]),ccus)
comcomp1a(20000,median(Congress.105[,28]),median(Congress.105[Resources==1,28]),length(Congress.105[Resources==1,1]),lcv)
comcomp1a(20000,median(Congress.105[,25]),median(Congress.105[Transportation.and.Infrastructure==1,25]),length(Congress.105[Transportation.and.Infrastructure==1,1]),ccus)
comcomp1a(20000,median(Congress.105[,28]),median(Congress.105[Transportation.and.Infrastructure==1,28]),length(Congress.105[Transportation.and.Infrastructure==1,1]),lcv)

#this function is Table 1 conditional on having to be a majority-rules committee

comcomp2a<-function(nreps,floorscore,commscore,commsize,IG)  {
    counter<-0
    committee<-0
    Repprop<-0
    allseen<-0
    MajorityCount<-0
while((allseen!=nreps)){
            committeerow<-sample(nrow(Congress.105),commsize,replace=FALSE)
            Repprop<-mean(Congress.105[committeerow,8])
            committee<-median(Congress.105[committeerow,IG])
            if(floorscore<=commscore&&committee>=commscore&&Repprop>.5){counter<-counter+1}
                    else if(floorscore>commscore&&committee<=commscore&&Repprop>.5){counter<-counter+1}
            if(Repprop>.5){MajorityCount<-MajorityCount+1}
                    proprepcom<-counter/nreps
                    if(MajorityCount==nreps){allseen<-nreps}
    }
    print(proprepcom)
}


comcomp2a(20000,median(Congress.105[,25]),median(Congress.105[Appropriations==1,25]),length(Congress.105[Appropriations==1,1]),25)
comcomp2a(20000,median(Congress.105[,25]),median(Congress.105[Budget==1,25]),length(Congress.105[Budget==1,1]),25)
comcomp2a(20000,median(Congress.105[,26]),median(Congress.105[Education.and.the.Workplace==1,26]),length(Congress.105[Education.and.the.Workplace==1,1]),26)
comcomp2a(20000,median(Congress.105[,27]),median(Congress.105[Education.and.the.Workplace==1,27]),length(Congress.105[Education.and.the.Workplace==1,1]),27)
comcomp2a(20000,median(Congress.105[,25]),median(Congress.105[Resources==1,25]),length(Congress.105[Resources==1,1]),25)
comcomp2a(20000,median(Congress.105[,28]),median(Congress.105[Resources==1,28]),length(Congress.105[Resources==1,1]),28)
comcomp2a(20000,median(Congress.105[,25]),median(Congress.105[Transportation.and.Infrastructure==1,25]),length(Congress.105[Transportation.and.Infrastructure==1,1]),25)
comcomp2a(20000,median(Congress.105[,28]),median(Congress.105[Transportation.and.Infrastructure==1,28]),length(Congress.105[Transportation.and.Infrastructure==1,1]),28)

#this function is Table 1 conditional on exact party proportion to that which really exists

comcomp3a<-function(nreps,floorscore,commscore,Demsize,Repsize,IG)   {
    counter<-0
    committee<-rnorm(nreps)
    committeecreate<-rnorm(nreps)
    DemContingent<-rnorm(nreps)
    RepContingent<-rnorm(nreps)
        for(i in 1:nreps){
            committee[i]<-median(committeecreate<-c((DemContingent<-sample(IG,Demsize,replace=FALSE,prob=DemProb)),(RepContingent<-sample(IG,Repsize,replace=FALSE, prob=RepProb))))
            if(floorscore<=commscore&&committee[i]>=commscore){counter<-counter+1}
            else if(floorscore>commscore&&committee[i]<=commscore){counter<-counter+1}
            proprepcom<-counter/nreps
            }
    print(median(committee))
    print(floorscore)
    print(commscore)
    print(proprepcom)
}

comcomp3a(20000,median(Congress.105[,25]),median(Congress.105[Appropriations==1,25]),length(Congress.105[Appropriations==1&Party==1,1]),length(Congress.105[Appropriations==1&Party==0,1]),ccus)
comcomp3a(20000,median(Congress.105[,25]),median(Congress.105[Budget==1,25]),length(Congress.105[Budget==1&Party==1,1]),length(Congress.105[Budget==1&Party==0,1]),ccus)
comcomp3a(20000,median(Congress.105[,26]),median(Congress.105[Education.and.the.Workplace==1,26]),length(Congress.105[Education.and.the.Workplace==1&Party==1,1]),length(Congress.105[Education.and.the.Workplace==1&Party==0,1]),cope)
comcomp3a(20000,median(Congress.105[,27]),median(Congress.105[Education.and.the.Workplace==1,27]),length(Congress.105[Education.and.the.Workplace==1&Party==1,1]),length(Congress.105[Education.and.the.Workplace==1&Party==0,1]),nea)
comcomp3a(20000,median(Congress.105[,25]),median(Congress.105[Resources==1,25]),length(Congress.105[Resources==1&Party==1,1]),length(Congress.105[Resources==1&Party==0,1]),ccus)
comcomp3a(20000,median(Congress.105[,28]),median(Congress.105[Resources==1,28]),length(Congress.105[Resources==1&Party==1,1]),length(Congress.105[Resources==1&Party==0,1]),lcv)
comcomp3a(20000,median(Congress.105[,25]),median(Congress.105[Transportation.and.Infrastructure==1,25]),length(Congress.105[Transportation.and.Infrastructure==1&Party==1,1]),length(Congress.105[Transportation.and.Infrastructure==1&Party==0,1]),ccus)
comcomp3a(20000,median(Congress.105[,28]),median(Congress.105[Transportation.and.Infrastructure==1,28]),length(Congress.105[Transportation.and.Infrastructure==1&Party==1,1]),length(Congress.105[Transportation.and.Infrastructure==1&Party==0,1]),lcv)

########################################################################################################

#the following functions relate to the "opposing outlier" hypothesis tested by Groseclose

comcomp4a<-function(nreps,floorscore,partyscore,commscore,commsize,IG)   {
    counter<-0
    committee<-rnorm(nreps)
        for (i in 1:nreps){
        committee[i]<-median(sample(IG,commsize,replace=FALSE,prob=DemProb))
        if(floorscore<partyscore&&committee[i]>=commscore){counter<-counter+1}
        else if(floorscore>partyscore&&committee[i]<=commscore){counter<-counter+1}
        proprepcom<-counter/nreps
        }
    print(summary(committee))
    print(median(committee))
    print(floorscore)
    print(partyscore)
    print(commscore)
    print(proprepcom)
}       

comcomp4a(20000,median(Congress.105[,25]),median(Congress.105[Party==1,25]),median(Congress.105[Appropriations==1&Party==1,25]),length(Congress.105[Appropriations==1&Party==1,1]),ccus)
comcomp4a(20000,median(Congress.105[,25]),median(Congress.105[Party==1,25]),median(Congress.105[Budget==1&Party==1,25]),length(Congress.105[Budget==1&Party==1,1]),ccus)
comcomp4a(20000,median(Congress.105[,26]),median(Congress.105[Party==1,26]),median(Congress.105[Education.and.the.Workplace==1&Party==1,26]),length(Congress.105[Education.and.the.Workplace==1&Party==1,1]),cope)
comcomp4a(20000,median(Congress.105[,27]),median(Congress.105[Party==1,27]),median(Congress.105[Education.and.the.Workplace==1&Party==1,27]),length(Congress.105[Education.and.the.Workplace==1&Party==1,1]),nea)
comcomp4a(20000,median(Congress.105[,25]),median(Congress.105[Party==1,25]),median(Congress.105[Resources==1&Party==1,25]),length(Congress.105[Resources==1&Party==1,1]),ccus)
comcomp4a(20000,median(Congress.105[,28]),median(Congress.105[Party==1,28]),median(Congress.105[Resources==1&Party==1,28]),length(Congress.105[Resources==1&Party==1,1]),lcv)
comcomp4a(20000,median(Congress.105[,25]),median(Congress.105[Party==1,25]),median(Congress.105[Transportation.and.Infrastructure==1&Party==1,25]),length(Congress.105[Transportation.and.Infrastructure==1&Party==1,1]),ccus)
comcomp4a(20000,median(Congress.105[,28]),median(Congress.105[Party==1,28]),median(Congress.105[Transportation.and.Infrastructure==1&Party==1,28]),length(Congress.105[Transportation.and.Infrastructure==1&Party==1,1]),lcv)

#the following function is Republican outlier not conditional on anything

comcomp5a<-function(nreps,floorscore,partyscore,commscore,commsize,IG)   {
    counter<-0
    committee<-rnorm(nreps)
        for (i in 1:nreps){
        committee[i]<-median(sample(IG,commsize,replace=FALSE,prob=RepProb))
        if(floorscore<partyscore&&committee[i]>=commscore){counter<-counter+1}
        else if(floorscore>partyscore&&committee[i]<=commscore){counter<-counter+1}
        proprepcom<-counter/nreps
        }
    print(summary(committee))
    print(median(committee))
    print(length(committee))
    print(floorscore)
    print(partyscore)
    print(commscore)
    print(proprepcom)
}

comcomp5a(20000,median(Congress.105[,25]),median(Congress.105[Party==0,25]),median(Congress.105[Appropriations==1&Party==0,25]),length(Congress.105[Appropriations==1&Party==0,1]),ccus)
comcomp5a(20000,median(Congress.105[,25]),median(Congress.105[Party==0,25]),median(Congress.105[Budget==1&Party==0,25]),length(Congress.105[Budget==1&Party==0,1]),ccus)
comcomp5a(20000,median(Congress.105[,26]),median(Congress.105[Party==0,26]),median(Congress.105[Education.and.the.Workplace==1&Party==0,26]),length(Congress.105[Education.and.the.Workplace==1&Party==0,1]),cope)
comcomp5a(20000,median(Congress.105[,27]),median(Congress.105[Party==0,27]),median(Congress.105[Education.and.the.Workplace==1&Party==0,27]),length(Congress.105[Education.and.the.Workplace==1&Party==0,1]),nea)
comcomp5a(20000,median(Congress.105[,25]),median(Congress.105[Party==0,25]),median(Congress.105[Resources==1&Party==0,25]),length(Congress.105[Resources==1&Party==0,1]),ccus)
comcomp5a(20000,median(Congress.105[,28]),median(Congress.105[Party==0,28]),median(Congress.105[Resources==1&Party==0,28]),length(Congress.105[Resources==1&Party==0,1]),lcv)
comcomp5a(20000,median(Congress.105[,25]),median(Congress.105[Party==0,25]),median(Congress.105[Transportation.and.Infrastructure==1&Party==0,25]),length(Congress.105[Transportation.and.Infrastructure==1&Party==0,1]),ccus)
comcomp5a(20000,median(Congress.105[,28]),median(Congress.105[Party==0,28]),median(Congress.105[Transportation.and.Infrastructure==1&Party==0,28]),length(Congress.105[Transportation.and.Infrastructure==1&Party==0,1]),lcv)

########################################################################################################

#the following does the representative committee hypothesis (Table 6)

comcomp6a<-function(nreps,floorscore,commscore,commsize,IG)  {
    counter<-0
    committee<-rnorm(nreps)
    proprepcom<-0
         for (i in 1:nreps)      {
                    committee[i]<-median(sample(IG,commsize,replace=FALSE))
                    }
                    if(commscore>median(committee)){proprepcom<-2*((length(committee[committee<=commscore])/nreps)-.5)}
                    else if(commscore==median(committee)){proprepcom<-(length(committee[committee==commscore])/nreps)}
                    else if(commscore<median(committee)){proprepcom<-2*(.5-(1-(length(committee[committee>=commscore])/nreps)))}
    print(summary(committee))
    print(length(committee))
    print(median(committee))
    print(floorscore)
    print(commscore)
    print(hist(committee))
    print(proprepcom)
}

comcomp6a(20000,median(Congress.105[,25]),median(Congress.105[Appropriations==1,25]),length(Congress.105[Appropriations==1,1]),ccus)
comcomp6a(20000,median(Congress.105[,25]),median(Congress.105[Budget==1,25]),length(Congress.105[Budget==1,1]),ccus)
comcomp6a(20000,median(Congress.105[,26]),median(Congress.105[Education.and.the.Workplace==1,26]),length(Congress.105[Education.and.the.Workplace==1,1]),cope)
comcomp6a(20000,median(Congress.105[,27]),median(Congress.105[Education.and.the.Workplace==1,27]),length(Congress.105[Education.and.the.Workplace==1,1]),nea)
comcomp6a(20000,median(Congress.105[,25]),median(Congress.105[Resources==1,25]),length(Congress.105[Resources==1,1]),ccus)
comcomp6a(20000,median(Congress.105[,28]),median(Congress.105[Resources==1,28]),length(Congress.105[Resources==1,1]),lcv)
comcomp6a(20000,median(Congress.105[,25]),median(Congress.105[Transportation.and.Infrastructure==1,25]),length(Congress.105[Transportation.and.Infrastructure==1,1]),ccus)
comcomp6a(20000,median(Congress.105[,28]),median(Congress.105[Transportation.and.Infrastructure==1,28]),length(Congress.105[Transportation.and.Infrastructure==1,1]),lcv)


#below is a function  for finding the proportion of committees that would fall in a range by chance conditional on majority-rules

comcomp7a<-function(nreps,floorscore,commscore,commsize,IG)  {
    committee<-matrix(0, nreps, 1)
    counter<-0
    Repprop<-0
    allseen<-0
    i <-0
    proprepcom<-0
while((allseen!=nreps)){
            committeerow<-sample(nrow(Congress.105),commsize, replace=FALSE)
            Repprop<-mean(Congress.105[committeerow,8])
            if(Repprop>.5){i<-i+1}
            if (Repprop>.5){committee[i,1]<-median(Congress.105[committeerow,IG])}
                    if(i==nreps){allseen<-nreps}
                    CongSim<-committee
    }
          if(commscore>median(committee)){proprepcom<-2*((length(CongSim[CongSim<=commscore])/nreps)-.5)}
                    else if(commscore==median(committee)){proprepcom<-(length(CongSim[CongSim==commscore])/nreps)}
                    else if(commscore<median(committee)){proprepcom<-2*(.5-(1-(length(CongSim[CongSim>=commscore])/nreps)))}         
    print(summary(committee))
    print(length(committee))
    print(median(committee))
    print(floorscore)
    print(commscore)
    print(proprepcom)
}

comcomp7a(20000,median(Congress.105[,25]),median(Congress.105[Appropriations==1,25]),length(Congress.105[Appropriations==1,1]),25)
comcomp7a(20000,median(Congress.105[,25]),median(Congress.105[Budget==1,25]),length(Congress.105[Budget==1,1]),25)
comcomp7a(20000,median(Congress.105[,26]),median(Congress.105[Education.and.the.Workplace==1,26]),length(Congress.105[Education.and.the.Workplace==1,1]),26)
comcomp7a(20000,median(Congress.105[,27]),median(Congress.105[Education.and.the.Workplace==1,27]),length(Congress.105[Education.and.the.Workplace==1,1]),27)
comcomp7a(20000,median(Congress.105[,25]),median(Congress.105[Resources==1,25]),length(Congress.105[Resources==1,1]),25)
comcomp7a(20000,median(Congress.105[,28]),median(Congress.105[Resources==1,28]),length(Congress.105[Resources==1,1]),28)
comcomp7a(20000,median(Congress.105[,25]),median(Congress.105[Transportation.and.Infrastructure==1,25]),length(Congress.105[Transportation.and.Infrastructure==1,1]),25)
comcomp7a(20000,median(Congress.105[,28]),median(Congress.105[Transportation.and.Infrastructure==1,28]),length(Congress.105[Transportation.and.Infrastructure==1,1]),28)


comcomp8a<-function(nreps,floorscore,commscore,Demsize,Repsize,IG)   {
    counter<-0
    committee<-rnorm(nreps)
    committeecreate<-rnorm(nreps)
    DemContingent<-rnorm(nreps)
    RepContingent<-rnorm(nreps)
         for (i in 1:nreps)      {
            committee[i]<-median(committeecreate<-c((DemContingent<-sample(IG,Demsize,replace=FALSE,prob=DemProb)),(RepContingent<-sample(IG,Repsize,replace=FALSE,prob=RepProb))))
                    }
                    if(commscore>median(committee)){proprepcom<-2*((length(committee[committee<=commscore])/nreps)-.5)}
                    else if(commscore==median(committee)){proprepcom<-(length(committee[committee==commscore])/nreps)}
                    else if(commscore<median(committee)){proprepcom<-2*((length(committee[committee>=commscore])/nreps)-.5)}
    print(summary(committee))
    print(length(committee))
    print(median(committee))
    print(floorscore)
    print(commscore)
    print(proprepcom)
}

comcomp8a(20000,median(Congress.105[,25]),median(Congress.105[Appropriations==1,25]),length(Congress.105[Appropriations==1&Party==1,1]),length(Congress.105[Appropriations==1&Party==0,1]),ccus)
comcomp8a(20000,median(Congress.105[,25]),median(Congress.105[Budget==1,25]),length(Congress.105[Budget==1&Party==1,1]),length(Congress.105[Budget==1&Party==0,1]),ccus)
comcomp8a(20000,median(Congress.105[,26]),median(Congress.105[Education.and.the.Workplace==1,26]),length(Congress.105[Education.and.the.Workplace==1&Party==1,1]),length(Congress.105[Education.and.the.Workplace==1&Party==0,1]),cope)
comcomp8a(20000,median(Congress.105[,27]),median(Congress.105[Education.and.the.Workplace==1,27]),length(Congress.105[Education.and.the.Workplace==1&Party==1,1]),length(Congress.105[Education.and.the.Workplace==1&Party==0,1]),nea)
comcomp8a(20000,median(Congress.105[,25]),median(Congress.105[Resources==1,25]),length(Congress.105[Resources==1&Party==1,1]),length(Congress.105[Resources==1&Party==0,1]),ccus)
comcomp8a(20000,median(Congress.105[,28]),median(Congress.105[Resources==1,28]),length(Congress.105[Resources==1&Party==1,1]),length(Congress.105[Resources==1&Party==0,1]),lcv)
comcomp8a(20000,median(Congress.105[,25]),median(Congress.105[Transportation.and.Infrastructure==1,25]),length(Congress.105[Transportation.and.Infrastructure==1&Party==1,1]),length(Congress.105[Transportation.and.Infrastructure==1&Party==0,1]),ccus)
comcomp8a(20000,median(Congress.105[,28]),median(Congress.105[Transportation.and.Infrastructure==1,28]),length(Congress.105[Transportation.and.Infrastructure==1&Party==1,1]),length(Congress.105[Transportation.and.Infrastructure==1&Party==0,1]),lcv)


########################################################################################################

#the following does the Democratic representative committee hypothesis (Table 7)

#For the 105th, the Republicans are in charge, so we should test for Republican party representativeness.  
#I will do the Democrats first, and then the Republicans

#Democrats
comcomp9a<-function(nreps,Demfloorscore,Demcommscore,Demcommsize,ADA)    {
    counter<-0
    committee<-rnorm(nreps)
    proprepcom<-0
         for (i in 1:nreps)      {
                    committee[i]<-median(sample(ADA97,Demcommsize,replace=FALSE,prob=DemProb))
                    }
                    if(Demcommscore>Demfloorscore){proprepcom<-2*((length(committee[committee<=Demcommscore])/nreps)-.5)}
                    else if(Demcommscore==Demfloorscore){proprepcom<-(length(committee[committee==Demcommscore])/nreps)}
                    else if(Demcommscore<Demfloorscore){proprepcom<-2*((length(committee[committee>=Demcommscore])/nreps)-.5)}
    print(proprepcom)
}



comcomp9a(20000,median(Congress.105[Party==1,"ADA97"]),median(Congress.105[Appropriations==1&Party==1,"ADA97"]),length(Congress.105[Appropriations==1&Party==1,1]),ADA97)
comcomp9a(20000,median(Congress.105[Party==1,"ADA97"]),median(Congress.105[Commerce==1&Party==1,"ADA97"]),length(Congress.105[Commerce==1&Party==1,1]),ADA97)
comcomp9a(20000,median(Congress.105[Party==1,"ADA97"]),median(Congress.105[Rules==1&Party==1,"ADA97"]),length(Congress.105[Rules==1&Party==1,1]),ADA97)
comcomp9a(20000,median(Congress.105[Party==1,"ADA97"]),median(Congress.105[Ways.and.Means==1&Party==1,"ADA97"]),length(Congress.105[Ways.and.Means==1&Party==1,1]),ADA97)
comcomp9a(20000,median(Congress.105[Party==1,"ADA97"]),median(Congress.105[Science==1&Party==1,"ADA97"]),length(Congress.105[Science==1&Party==1,1]),ADA97)
comcomp9a(20000,median(Congress.105[Party==1,"ADA97"]),median(Congress.105[Transportation.and.Infrastructure==1&Party==1,"ADA97"]),length(Congress.105[Transportation.and.Infrastructure==1&Party==1,1]),ADA97)
comcomp9a(20000,median(Congress.105[Party==1,"ADA97"]),median(Congress.105[Veteran.Affairs==1&Party==1,"ADA97"]),length(Congress.105[Veteran.Affairs==1&Party==1,1]),ADA97)
comcomp9a(20000,median(Congress.105[Party==1,"ADA97"]),median(Congress.105[House.Oversight==1&Party==1,"ADA97"]),length(Congress.105[House.Oversight==1&Party==1,1]),ADA97)
comcomp9a(20000,median(Congress.105[Party==1,"ADA97"]),median(Congress.105[Government.Reform.and.Oversight==1&Party==1,"ADA97"]),length(Congress.105[Government.Reform.and.Oversight==1&Party==1,1]),ADA97)

#Republicans

comcomp9b<-function(nreps,Repfloorscore,Repcommscore,Repcommsize,ADA)    {
    counter<-0
    committee<-rnorm(nreps)
    proprepcom<-0
         for (i in 1:nreps)      {
                    committee[i]<-median(sample(ADA97,Repcommsize,replace=FALSE, prob=RepProb))
                    }
                    if(Repcommscore>Repfloorscore){proprepcom<-2*((length(committee[committee<=Repcommscore])/nreps)-.5)}
                    else if(Repcommscore==Repfloorscore){proprepcom<-(length(committee[committee==Repcommscore])/nreps)}
                    else if(Repcommscore<Repfloorscore){proprepcom<-2*((length(committee[committee>=Repcommscore])/nreps)-.5)}
    print(summary(committee))
    print(length(committee))
    print(median(committee))
    print(Repfloorscore)
    print(Repcommscore)
    print(proprepcom)
}

comcomp9b(20000,median(Congress.105[Party==0,"ADA97"]),median(Congress.105[Appropriations==1&Party==0,"ADA97"]),length(Congress.105[Appropriations==1&Party==0,1]),ADA97)
comcomp9b(20000,median(Congress.105[Party==0,"ADA97"]),median(Congress.105[Commerce==1&Party==0,"ADA97"]),length(Congress.105[Commerce==1&Party==0,1]),ADA97)
comcomp9b(20000,median(Congress.105[Party==0,"ADA97"]),median(Congress.105[Rules==1&Party==0,"ADA97"]),length(Congress.105[Rules==1&Party==0,1]),ADA97)
comcomp9b(20000,median(Congress.105[Party==0,"ADA97"]),median(Congress.105[Ways.and.Means==1&Party==0,"ADA97"]),length(Congress.105[Ways.and.Means==1&Party==0,1]),ADA97)
comcomp9b(20000,median(Congress.105[Party==0,"ADA97"]),median(Congress.105[Science==1&Party==0,"ADA97"]),length(Congress.105[Science==1&Party==0,1]),ADA97)
comcomp9b(20000,median(Congress.105[Party==0,"ADA97"]),median(Congress.105[Transportation.and.Infrastructure==1&Party==0,"ADA97"]),length(Congress.105[Transportation.and.Infrastructure==1&Party==0,1]),ADA97)
comcomp9b(20000,median(Congress.105[Party==0,"ADA97"]),median(Congress.105[Veteran.Affairs==1&Party==0,"ADA97"]),length(Congress.105[Veteran.Affairs==1&Party==0,1]),ADA97)
comcomp9b(20000,median(Congress.105[Party==0,"ADA97"]),median(Congress.105[House.Oversight==1&Party==0,"ADA97"]),length(Congress.105[House.Oversight==1&Party==0,1]),ADA97)
comcomp9b(20000,median(Congress.105[Party==0,"ADA97"]),median(Congress.105[Government.Reform.and.Oversight==1&Party==0,"ADA97"]),length(Congress.105[Government.Reform.and.Oversight==1&Party==0,1]),ADA97)
